package com.cxs.plan.controller.bill;

import com.cxs.plan.constant.MonthEnum;
import com.cxs.plan.constant.Views;
import com.cxs.plan.domain.HttpResult;
import com.cxs.plan.domain.entity.PayVariation;
import com.cxs.plan.service.PayVariationService;
import com.cxs.plan.utils.PageUtil;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/bill/variation")
public class PayVariationController {

    @Autowired
    private PayVariationService payVariationService;

    @Autowired
    private PageUtil pageUtil;

    @ApiOperation(value = "获取用户支付类型")
    @GetMapping("/type")
    public HttpResult getUserPayType() {
        Object userPayType = payVariationService.getUserPayType();
        return HttpResult.success(userPayType);
    }

    @ApiOperation(value = "获取用户支付卡")
    @GetMapping("/card")
    public HttpResult getUserPayCard() {
        return HttpResult.success(payVariationService.getUserPayCard());
    }

    @ApiOperation(value = "添加消费/收入记录")
    @PostMapping
    public HttpResult addPayVariation(@Validated @RequestBody PayVariation payVariation) {
        payVariationService.savePayVariation(payVariation);
        return HttpResult.success();
    }

    @ApiOperation(value = "获取消费/收入记录列表")
    @GetMapping
    public HttpResult payVariationList(Integer billId) {
        return HttpResult.success(pageUtil.autoPage(payVariationService.getPayVariationList(billId)));
    }

    @ApiOperation(value = "获取账单列表")
    @GetMapping("bill")
    public HttpResult getBillList() {
        return HttpResult.success(payVariationService.getBillList());
    }

    @ApiOperation(value = "根据日期获取消费/收入记录")
    @GetMapping("/record")
    public HttpResult getPayVariationByDate(String date) {

        return HttpResult.success(payVariationService.getPayVariationByDate(date));
    }

    @GetMapping("/record/month")
    public HttpResult getPayVariationByMonth(String date) {
        return HttpResult.success(payVariationService.getPayVariationMonthByDate(date));
    }
}
